﻿using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Domain.Entities.Auditing;

namespace Coway.Ordering.Buyers
{
    /// <summary>
    /// 购买者
    /// </summary>
    public class Buyer : AuditedAggregateRoot<Guid>
    {
        /// <summary>
        /// 名字
        /// </summary>
        public string FirstName { get; set; }

        /// <summary>
        /// 姓氏
        /// </summary>
        public string LastName { get; set; }

        /// <summary>
        /// 社安号 xxx-xx-xxxx，如果选择租赁才需要填写此项
        /// </summary>
        public string SocialSecurityNumber { get; set; }

        public string SocialSecurityNumberFormat()
        {
            if (!string.IsNullOrWhiteSpace(this.SocialSecurityNumber) && this.SocialSecurityNumber.Length > 5)
            {
                return SocialSecurityNumber.Insert(3, "-").Insert(6, "-");
            }
            else
            {
                return SocialSecurityNumber;
            }
        }

        /// <summary>
        /// 出生日期（月/日/年）
        /// </summary>
        public DateTime? DateOfBirth { get; set; }

        /// <summary>
        /// 邮箱地址
        /// </summary>
        public string EMail { get; set; }

        /// <summary>
        /// 税号/营业登记号（TAX ID / BUSINESS REGISTRATION NUMBER:）
        /// </summary>
        public string TaxId { get; set; }

        /// <summary>
        /// 法律地址/住所 - 街道
        /// </summary>
        public string LegalAddressStreet { get; set; }

        /// <summary>
        /// 法律地址/住所 - 城市
        /// </summary>
        public string LegalAddressCity { get; set; }

        /// <summary>
        /// 法律地址/住所 - 州
        /// </summary>
        public string LegalAddressState { get; set; }

        /// <summary>
        /// 法律地址/住所 - 公寓住宅bai (单元住宅, 房间du)
        /// </summary>
        public string LegalAddressApt { get; set; }

        /// <summary>
        /// 法律地址/住所 - 邮编
        /// </summary>
        public string LegalAddressZipCode { get; set; }

        /// <summary>
        /// 账单地址 - 街道
        /// </summary>
        public string BillingAddressStreet { get; set; }

        /// <summary>
        /// 账单地址 - 城市
        /// </summary>
        public string BillingAddressCity { get; set; }

        /// <summary>
        /// 账单地址 - 州
        /// </summary>
        public string BillingAddressState { get; set; }

        /// <summary>
        /// 账单地址 - 公寓住宅bai (单元住宅, 房间du)
        /// </summary>
        public string BillingAddressApt { get; set; }

        /// <summary>
        /// 账单地址 - 邮编
        /// </summary>
        public string BillingAddressZipCode { get; set; }

        /// <summary>
        /// 家庭电话
        /// </summary>
        public string HomePhone { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        public string Mobile { get; set; }

        /// <summary>
        /// 家庭电话
        /// </summary>
        public string HomePhoneFormat()
        {
            return InnerPhoneFormat(this.HomePhone);
        }

        /// <summary>
        /// 手机号码
        /// </summary>
        public string MobileFormat()
        {
            return InnerPhoneFormat(this.Mobile);
        }

        private string InnerPhoneFormat(string phone)
        {
            if (!string.IsNullOrWhiteSpace(phone) && phone.Length > 6)
            {
                return phone.Insert(0, "(").Insert(4, ")").Insert(8, "-");
            }
            else
            {
                return phone;
            }
        }
    }
}
